/*=====================================================================================================================
                    Copyright(c) 2005 Geometric PLM Software Corp. All rights reserved.
                             Unpublished - All rights reserved
=======================================================================================================================
File description:
    Filename: string_utils.h
    Module  : Common module.

        This file includes some operations of the string.

=======================================================================================================================
Date               Name              Description of Change
14-Jul-2009        Penn,Xie          Initialize creation
$HISTORY$
=====================================================================================================================*/
#ifndef STRING_UTILS_H
#define STRING_UTILS_H

#ifdef __cplusplus
    extern "C"
    {
#endif

// @{{ String assister
#define IS_NULL(S)   ((S)==NULL)
#define IS_EMPTY(S)  (((S)==NULL) || !(*(S)))
// @}}

    /**
    * Clones the string.
    * @param dst - <OF> the output string.
    * @param src - <I>  the string to be cloned.
    * @return - the destinatin string pointer.
    */
    extern char* GSTR_clone( char **dst, const char *src );

    /**
    * Copy safely the string with null end.
    * @param dst - <O> the output string.
    * @param src - <I>  the string to be cloned.
    * @param dstSize - <I> the size of output string.
    * @return - the destinatin string pointer.
    */
    extern char *GSTR_copy( char *dst, const char *src, int dstSize );

    /**
    * Converts int to string.
    * @param dst   - <OF> the output string.
    * @param value - <I>  the int to be cloned.
    * @return - the destinatin string pointer.
    */
    extern char* GSTR_int_to_string( char **dst, int value );

    /**
    * Formats the int value as string.
    * @param dst      - <O> the destination string.
    * @param digitNum - <I> the digit number of the value.
    * @param value    - <I> the value to be converted.
    * @return - N/A.
    */
    extern void GSTR_format_int_to_string( char *dst, int digitNum, int value );

    /**
    * Appends the strings( never null returned )
    * @param s1 - <I> string 1
    * @param s2 - <I> string 2
    * @return - <OF> new string
    */
    extern char* GSTR_string_append( const char *s1, const char *s2 );

    /**
    * convert string to int
    * @param srcString - <I> the source string
    * @param delimiter - <O> the result of converting
    * @return - return true if convert success, else return false
    */
    extern logical GSTR_string_to_int(const char* strValue, int *intValue);

    /**
    * Whether the string is float type
    * @param count - <I> The string count
    * @param str   - <I> The string
    *
    *   NOTE: it's only check whether each word is in "+-.0123456789", not care the float with "E" or the float rule, 
    *         like "00-1.+01", it will return true.
    * @return - return true if it is one.
    */
    extern logical GSTR_is_float(const char *str);

    /**
    * Trims the string's prefix.
    * @param str - <I> The string
    * @param s   - <I> The char
    *
    * @return - count.
    */
    extern int GSTR_trim_l( char *str, char s );
    extern int GSTR_trim_r( char *str, char s );

    /**
    * Remove the zero.
    *   For Example:
    *       floatValue="50.00"   -> = "50"
    *       floatValue="50.0100" -> = "50.01"
    * @return - count.
    */
    extern void GSTR_trim_float( char *floatValue );
	extern char* GSTR_replace_str( char *str );


#ifdef __cplusplus
    }
#endif


#endif //STRING_UTILS_H
